import os
import cv2
import tensorflow as tf
%matplotlib inline
from matplotlib import pyplot as plt
input_dir = '/code/research/images/mcw_he_stylegan_fakes'
def display_histogram_and_image(subdir, dirs, file):
img = cv2.imread(os.path.join(subdir, file))
fig, ax = plt.subplots(1,2, figsize=(20,10))
ax[0].imshow(img)
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv2.calcHist([img],[i],None,[256],[0,256])
ax[1].plot(histr,color = col)
plt.title(file)
plt.show()
def walk_through_dir_and_print_histograms(directory,max_plots=2):
count = 0
for subdir, dirs, files in os.walk(directory):
for file in files:
filepath = os.path.join(subdir, file)
file_name, file_extension = os.path.splitext(file)
if file_extension == '.png':
display_histogram_and_image(subdir, dirs, file)
count += 1
if count == max_plots:
return 0
1024 x 1024 pngs
walk_through_dir_and_print_histograms(input_dir, max_plots=25)
1024 x 1024 pngs
input_dir = '/code/research/images/peso_input_images'
walk_through_dir_and_print_histograms(input_dir, max_plots=25)